# encoding: utf-8
# @File  : test07_ht_login.py
# @Author: wu shaofan
# @Date  :  2024/04/29
# @Desc :
import json
import allure
import pytest
import config
import conftest
from PO.page.page_ht_login import PageHtLogin
from Utils.get_driver import GetDriver
from Utils.record_log import Log


@allure.feature('4、后台登录')
class TestLogin:
    def setup_class(self):
        # TODO 获取driver
        self.driver = GetDriver().get_driver(config.ht_login_url)
        # 异常截图
        conftest.driver = self.driver
        # 获取登录对象
        self.login = PageHtLogin(self.driver)
        # 获取日志对象
        self.log = Log("后台登录成功用例").get_logger()

    def teardown_class(self):
        # 关闭driver
        GetDriver().close_driver()
        Log("后台登录失败用例").write_empty_line()

    @allure.story('1、登录成功')
    def test_login01_success(self):
        with allure.step('步骤一：输入用户名'):
            self.login.page_input_username(config.ht_testdata['后台用户名'])

        with allure.step('步骤二：输入密码'):
            self.login.page_input_password(config.ht_testdata['密码'])

        with allure.step('步骤三：输入验证码'):
            self.login.page_input_verify_code(config.ht_testdata['验证码'])

        with allure.step('步骤四：点击登录按钮'):
            self.login.page_click_login_btn()

        data = {
            "后台登录成功数据": config.ht_testdata
        }
        self.log.info(f"后台登录成功：{data}")
        data = json.dumps(data, ensure_ascii=False, indent=4)
        allure.attach(data, "后台登录成功", allure.attachment_type.JSON)


if __name__ == '__main__':
    pytest.main()
